import 'package:flutter/material.dart';

import 'package:sow_app_i18n/sow_app_i18n.dart';

import '../info_page.dart';

class BecomeAuthorPage extends StatefulWidget {
  const BecomeAuthorPage({Key? key, required this.onConfirm}) : super(key: key);
  static const routeName = '${InfoPage.routeName}/become_author';

  @override
  BecomeAuthorPageState createState() {
    return BecomeAuthorPageState();
  }

  final void Function() onConfirm;
}

class BecomeAuthorPageState extends State<BecomeAuthorPage> {
  final _formKey = GlobalKey<FormState>();
  String penName = '';
  String desc = '';
  String inviteCode = '';
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(I18n.become_author),
      ),
      body: Form(
        key: _formKey,
        child: Column(
          children: [
            TextFormField(
              keyboardType: TextInputType.text,
              decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: '笔名',
              ),
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return "笔名不能为空";
                }
                penName = value;
                return null;
              },
            ),
            TextFormField(
              keyboardType: TextInputType.text,
              decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: '简介',
              ),
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return "简介不能为空";
                }
                desc = value;
                return null;
              },
            ),
            TextFormField(
              keyboardType: TextInputType.text,
              decoration: const InputDecoration(
                border: UnderlineInputBorder(),
                labelText: '邀请码',
              ),
              validator: (value) {
                inviteCode = value ?? '';
                return null;
              },
            ),
            ElevatedButton(
              onPressed: () {
                if (_formKey.currentState!.validate()) {
                  print([penName, desc, inviteCode].join(','));
                  widget.onConfirm();
                }
              },
              child: const Text(I18n.submit),
            ),
            Expanded(
                child: Icon(
              Icons.history_edu,
              color: Colors.grey.shade300,
              size: 240,
            ))
          ],
        ),
      ),
    );
  }
}
